let _pool = {};
export default class CustomValue2D extends Laya.Value2D {
    vs: string;
    ps: string;
    constructor(vs, ps, subID = new Date().getTime()) {
        // let subID = new Date().getTime();
        super(Laya.ShaderDefines2D.TEXTURE2D, subID);
        this.vs = vs;
        this.ps = ps;
        // 着色器attri参数名称和index对应信息，laya底层会处理这个

    }

    public setAttribLocation(attribLoaction, shader = null, subID?) {
        this._attribLocation = [];
        for (let i = 0; i < attribLoaction.length; i++) {
            this._attribLocation.push(attribLoaction[i][0], i);
        }
        if (shader) {
            this.shader = shader;
            return;
        }
        this.shader = new Laya.Shader2X(this.vs, this.ps, Laya.ShaderDefines2D.TEXTURE2D | (subID || this.subID), null, this._attribLocation);
    }

    public static createOne(vs, ps, id) {
        if (!_pool[id]) {
            _pool[id] = [];
        }
        if (_pool[id].length == 0) {
            let value = new CustomValue2D(vs, ps, 111);
            return value;
        } else {
            return _pool[id].pop();
        }
    }

    upload(): void {
        this.texture = null;
        super.upload();
        let p = _pool[this.subID];
        p.push(this);
    }
}